package com.yh.threadTest.pojo;

/**
 * @ClassName TestState
 * @Description TODO
 * @Author 0715-YuHao
 * @Date 2020/11/14 13:19
 */
public class TestState implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i == 50) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
        Runnable r = new TestState();
        Thread t = new Thread(r, "a");
        Thread t2 = new Thread(r, "b");

        Thread.State state = t.getState();
        System.out.println(state);

        t.start();
        state = t.getState();
        System.out.println(state);

        while (state != Thread.State.TERMINATED) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            state = t.getState();
            System.out.println(state);
        }
    }
}
